#!/usr/bin/python
#-*- coding: utf-8 -*-

# CPBMI Python Homework 8-1
# Programmed by Seunghwan Kim

import sys, os, re

agehash = {}
filelist = os.listdir("SEER")
os.chdir("SEER")

for file in filelist:
    infile = open(file, 'r')
    for line in infile:
        age = line[24:27]
        if re.search(r'[01][0-9]{2}', age):
            if agehash.has_key(age):
                agehash[age] = agehash[age] +1
            else:
                agehash[age] = 1
    infile.close()
    
    keylist = agehash.keys()
    keylist.sort()
    outfile = open(file[0:-3] + 'output', 'w')
    for item in keylist:
        outfile.write("%s\t%d\n" % (item, agehash[item]))
    outfile.close()
